﻿/****************************************************************************************************************
*                                                                                                               *
* Copyright (C) 2011 5173.com                                                                                   *
* This project may be copied only under the terms of the Apache License 2.0.                                    *
* Please visit the project Home Page http://bqqapicsharp.codeplex.com/ for more detail.                         *
*                                                                                                               *
****************************************************************************************************************/

namespace BQQAPIClient.Core.Protocol
{
    using System.Collections.Generic;
    using BQQAPIClient.Core.Business;
    using BQQAPIClient.Core.Utility;

    internal class SetKefuStatusPackage : AbstractOperationPackage
    {
        private KefuStatusList kefuStatusList;

        internal SetKefuStatusPackage(KefuStatusList kefuStatusList)
        {
            this.kefuStatusList = kefuStatusList;
        }

        protected override TLVList OtherData
        {
            get
            {
                var tlvList = new TLVList();
                tlvList.Add(new TLV(KefuStatusList.TCount, ((ushort)kefuStatusList.Count).GetBigEndianBytes()));

                var kefuIDBytes = new List<byte>();
                kefuStatusList.ForEach(kefuStatus => kefuIDBytes.AddRange(kefuStatus.KefuID.GetBigEndianBytes()));
                tlvList.Add(new TLV(KefuStatus.TKefuID, kefuIDBytes.ToArray()));
                
                var kefuStatusEnumBytes = new List<byte>();
                kefuStatusList.ForEach(kefuStatus => kefuStatusEnumBytes.AddRange(((ushort)kefuStatus.KefuStatusEnum).GetBigEndianBytes()));
                tlvList.Add(new TLV(KefuStatus.TkefuStatusEnum, kefuStatusEnumBytes.ToArray()));

                var kefuMaxAutoAssignCountBytes = new List<byte>();
                kefuStatusList.ForEach(kefuStatus => kefuMaxAutoAssignCountBytes.AddRange(kefuStatus.MaxAutoAssignCount.GetBigEndianBytes()));
                tlvList.Add(new TLV(KefuStatus.TMaxAutoAssignCount, kefuMaxAutoAssignCountBytes.ToArray()));

                var kefuIsHostBySystemBytes = new List<byte>();
                kefuStatusList.ForEach(kefuStatus => kefuIsHostBySystemBytes.Add(kefuStatus.IsHostBySystem));
                tlvList.Add(new TLV(KefuStatus.TisHostBySystem, kefuIsHostBySystemBytes.ToArray()));

                return tlvList;
            }
        }

        protected override ushort Cmd
        {
            get
            {
                return 22;
            }
        }

        protected override ushort SubCmd
        {
            get
            {
                return 105;
            }
        }
    }
}
